<template>
  <div class="home_container">
    <img class="home_loginImg" src="@/assets/images/login_effect.png" />
    <div class="login_form_container">
      <div class="login_form">
        <div class="login_form_title">
          <div class="login_form_title_text">登录</div>
          <div class="login_form_title_img">LOGIN</div>
        </div>
        <el-form
          ref="ruleFormRef"
          :model="FormData"
          :rules="rules"
          label-width="120px"
          label-position="top"
          class="login_form_main"
        >
          <el-form-item label="用户名" prop="userName">
            <el-input v-model="FormData.userName" placeholder="请输入用户名" />
          </el-form-item>
          <br />
          <el-form-item label="密&nbsp;&nbsp&nbsp;&nbsp码" prop="userPass">
            <el-input
              v-model="FormData.userPass"
              type="password"
              placeholder="请输入密码"
              show-password
            />
          </el-form-item>
          <br />
          <el-checkbox
            v-model="IsSaveP"
            label="记住密码"
            size="large"
            style="margin-left: 10px"
          />
          <div class="button_login" @click="Login">登录</div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { LoginApi } from "@/services/login.js";
export default {
  name: "login",
  data() {
    return {
      FormData: {
        userName: "",
        userPass: "",
      },
      IsSaveP: true,
      rules: {
        userName: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 1,
            max: 20,
            message: "用户名输入3到5位",
            trigger: "blur",
          },
        ],
        userPass: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  mounted() {
    // let p = this.$router;
    // console.log(p, "p");
    // console.log(this.$route, "route");
  },
  methods: {
    Login() {
      const ref = this.$refs.ruleFormRef;
      ref.validate(async (isPass) => {
        if (isPass) {
          let res = await LoginApi(this.FormData);
          if (res?.respCode == 200) {
            this.$store.commit("updateToken", res.respData.token);
            this.$message.success(res.respMessage);
            this.$router.push("/");
          } else {
            this.$message.error(res.respMessage);
          }
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.home_container {
  width: 100%;
  height: 100%;
  background-image: url("~@/assets/images/index_bg.jpg");
  background-size: 100% 100%;
  overflow: auto;
  position: relative;
  .home_loginImg {
    position: absolute;
    top: 10%;
    right: 50%;
    width: 655px;
    height: 650px;
  }

  .login_form_container {
    position: absolute;
    top: 20%;
    left: 54%;
    width: 567.547px;
    height: 594.29px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;

    .login_form {
      position: absolute;
      inset: 54.107px;

      .login_form_title {
        display: flex;

        .login_form_title_text {
          width: 60px;
          height: 52px;
          line-height: 52px;
          color: #ffffff;
          font-size: 30px;
          font-weight: bold;
          border-bottom: 2px solid #557dff;
        }

        .login_form_title_img {
          font-size: 42px;
          font-weight: bolder;
          background-image: -webkit-linear-gradient(left, #a5dbf3, #4857ff);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
        }
      }

      .login_form_main {
        margin-top: 60px;

        :deep(.el-form-item .el-form-item__label) {
          font-size: 22px;
          color: #ffffff;
        }

        :deep(.el-input__wrapper) {
          background-color: transparent;
          border-bottom: 1px solid #8e98af;
          box-shadow: 0 0 0 0;
        }

        :deep(.el-input__inner) {
          color: #ffffff;
        }

        .button_login {
          margin: 30px auto 0;
          width: 50%;
          height: 54px;
          line-height: 54px;
          cursor: pointer;
          text-align: center;
          font-size: 24px;
          color: #ffffff;
          background: -webkit-gradient(
            linear,
            0 0,
            100% 0,
            from(#42c2db),
            to(#557dff)
          );
          border-radius: 50px 50px 50px 50px;
          filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=#42c2db, endcolorstr=#557dff, gradientType=1);
        }
      }
    }
  }
}
</style>
